package com.fang.tcptest;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class TestServer extends Thread {
    private ServerSocket serverSocket;

    public TestServer() {
        super("服务器：");
    }

    @Override
    public void run() {
        try {
            serverSocket = new ServerSocket(8090);
            Socket socket = serverSocket.accept();
            BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            while(true){
                String strRead =  br.readLine();
                System.out.println(strRead);

                /////////////////////////////发送消息///////////////////////////////////

                BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
                Scanner sc = new Scanner(System.in);
                String strWrite = sc.next();
                bw.write(this.getName()+strWrite);
                bw.newLine();
                System.out.println(this.getName()+strWrite);
                bw.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
